<template>
  <div class="order">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column prop="orderId" label="订单号"> </el-table-column>
      <el-table-column prop="orderStatus" label="订单状态">
        <template slot-scope="scope">
          <div v-if="String(scope.row.orderStatus) === '1'">待付款</div>
          <div v-if="String(scope.row.orderStatus) === '2'">待接单</div>
          <div v-if="String(scope.row.orderStatus) === '3'">待派送</div>
          <div v-if="String(scope.row.orderStatus) === '4'">已派送</div>
          <div v-if="String(scope.row.orderStatus) === '5'">已完成</div>
          <!-- {{ String(scope.row.orderStatus) === '0' ? '停售' : '启售' }} -->
        </template>
      </el-table-column>
      <el-table-column prop="orderConsignee" label="用户名"> </el-table-column>
      <el-table-column prop="orderPhone" label="手机号"> </el-table-column>

      <el-table-column prop="orderAddress" label="地址"> </el-table-column>
      <el-table-column prop="createTime" label="下单时间"> </el-table-column>

      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <el-button type="warning" round v-if="String(scope.row.orderStatus) === '2'">接单</el-button>
          <el-button type="warning" round v-if="String(scope.row.orderStatus) === '4'">完成</el-button>
          <el-button type="warning" round v-if="String(scope.row.orderStatus) === '3'">派送</el-button>
          <el-button type="warning" round
            v-if="String(scope.row.orderStatus) === '1' || String(scope.row.orderStatus) === '2'"
            @click="reject()" v-show="flag">拒单</el-button>
          <el-button type="warning" round>查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]" :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getPage } from '@/api/order';
export default {
  data() {
    return {
      flag:true,
      total: 0,
      listQuery: {
        pageNo: 1,
        pageSize: 10
      },
      currentPage: 5,

      tableData: []

    }
  },
  created() {
    this.init();
  },
  methods: {
    reject() {
      this.$confirm('确认拒单?, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '拒单成功!'
        });
        this.flag = false
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消拒单'
        });
      });

    },
    init() {
      getPage(this.listQuery)
        .then((res) => {
          this.tableData = res.data.records;
          this.total = res.data.total
        })


    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.listQuery.pageNo = val
      console.log(`当前页: ${val}`);
    }

  }
}
</script>

<style lang="scss">
.order {
  .el-table .cell {
    // font-size: 20px;
    text-align: center;
  }
}
</style>

